package com.wanshi.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

        System.out.println("-------------------------------发生异常");

        String message = null;

        if(e instanceof  MyException){
            message = e.getMessage();
        }else{
            message = "未知错误,请联系管理员15555555555!";
        }

        ModelAndView mv= new ModelAndView();
        if("请先登录".equals(message)){
            mv.addObject("error",message);
            mv.setViewName("login");
            return mv;
        }
        mv.addObject("error",message);
        mv.setViewName("error");
        return mv;
    }
}
